//package com.lin.manager;
//
//import com.lin.manager.mq.entity.MqMessageeEntity;
//import com.lin.manager.mq.service.MqMessageService;
//import com.lin.manager.notice.NoticeBusinessHandle;
//import com.lin.manager.notice.service.NoticeService;
//import com.lin.manager.rabbitmq.service.BusinessHandle;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//import java.io.IOException;
//
///**
// * @作者: 林江
// * @创建时间: 2024/4/14
// * @功能:
// */
//@Slf4j
//@Component
//public class HandleMessage {
//    @Autowired
//    private MqMessageService mqMessageService;
//    @Autowired
//    private NoticeService noticeService;
//
//    @RabbitListener(queues = "notice_dead_queue", containerFactory = "simpleRabbitListenerContainerFactory")
//    public void handlerNoticeMessage(Message message, Channel channel) throws IOException {
//        NoticeBusinessHandle service = new NoticeBusinessHandle();
//        service.setNoticeService(noticeService);
//        doMessage(message, channel, service);
//    }
//
//    @RabbitListener(queues = "other_dead_queue", containerFactory = "simpleRabbitListenerContainerFactory")
//    public void handlerOtherMessage(Message message, Channel channel) throws IOException {
//        log.info("处理other消息。。。。。");
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        channel.basicAck(deliveryTag, false);
//    }
//
//    /**
//     * 处理消息
//     *
//     * @param message
//     * @param channel
//     * @param handler
//     * @throws IOException
//     */
//    private void doMessage(Message message, Channel channel, BusinessHandle handler) throws IOException {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        String correlationId = message.getMessageProperties().getCorrelationId();
//        log.info("标签：{}，消息id：{}", deliveryTag, correlationId);
//        if (StringUtils.hasText(correlationId)) {
//            MqMessageeEntity mqMessagee = mqMessageService.getById(correlationId);
//            if (mqMessagee.getStatus() == 2) {
//                channel.basicAck(deliveryTag, false);
//            } else {
//                try {
//                    // 执行业务逻辑
//                    handler.doBusiness(message);
//                    mqMessageService.updateStatus(correlationId, 2, null);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    mqMessageService.updateStatus(correlationId, 3, e.getMessage());
//                    // Todo 日志推送给系统
//                }
//                channel.basicAck(deliveryTag, false);
//            }
//        } else {
//            channel.basicAck(deliveryTag, false);
//        }
//    }
//}
